package com.wb.spring.boot.autoconfigure.register;

import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

/**
 * @Author wenbin.xu
 * @Date 2022/9/9 11:11
 */
public class RedisSubscriber extends MessageListenerAdapter {

    private RedisRegister redisRegister;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        if ("\"register\"".equals(new String(message.getBody())) || "\"unregister\"".equals(new String(message.getBody()))) {
            redisRegister.refreshServer();
        }
    }

    public RedisSubscriber(RedisRegister redisRegister) {
        super();
        this.redisRegister = redisRegister;
    }
}
